package controller.menu;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import common.entities.Msg;
import entities.menu.MenuEntities;
import service.menu.MenuService;

/**
 * 菜单Controller
 * @author hxl
 *
 */
@Controller
@RequestMapping(value="/menu")
public class MenuController {
	@Resource
	MenuService menuService;
	
	@RequestMapping(value="/getAuthorizedMenu")
	@ResponseBody
	public MenuEntities getAuthorizedMenu(){
		return menuService.getAuthorizedMenu();
	}
	@RequestMapping(value="/getAllMenu")
	@ResponseBody
	public MenuEntities getAllMenu(){
		return menuService.getAllMenu();
	}
	
	@RequestMapping(value="/addMenu")
	@ResponseBody
	public boolean addMenu(
			@RequestParam(value = "id",required = true)String id,
			@RequestParam(value = "level",required = true)int level,
			@RequestParam(value = "location",required = true)int location,
			@RequestParam(value = "name",required = false,defaultValue = "")String name,
			@RequestParam(value = "path",required = false,defaultValue = "")String path,
			@RequestParam(value = "type",required = true)int type,
			HttpServletRequest req){
			menuService.addMenu(type,id,level,location,name, path,req);
			return true;
	}
	
   	/**
   	 * 删除菜单
   	 * @param id
   	 */
	@RequestMapping(value="/deleteMenu")
	@ResponseBody
	public boolean deleteMenu(@RequestParam(value = "id",required = true)String id){
	    menuService.deleteMenu(id);
	    return true;
	}

}
